//
//  NewsViewController.m
//  QQ_Youngsher
//
//  Created by Maxwell on 16/1/14.
//  Copyright © 2016年 LLLTeam. All rights reserved.
//

#import "NewsViewController.h"
#import "NewsListTableViewController.h"
#import "PhoneListTableViewController.h"

#define SCREEN_W [[UIScreen mainScreen] bounds].size.width
#define SCREEN_H [[UIScreen mainScreen] bounds].size.height

@interface NewsViewController ()

@property (nonatomic ,strong)UIView *newsListTableView;
@property (nonatomic ,strong)UIView *phoneListTableView;


@end

@implementation NewsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    UIBarButtonItem *leftBarButtonItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"contact_y"] style:(UIBarButtonItemStylePlain) target:self action:@selector(personalSetting:)];
    self.navigationItem.leftBarButtonItem = leftBarButtonItem;
    UIBarButtonItem *rightBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(add:)];
    self.navigationItem.rightBarButtonItem = rightBarButtonItem;
//    self.automaticallyAdjustsScrollViewInsets = NO;
//    self.navigationController.navigationBar.translucent = NO;
    self.edgesForExtendedLayout = UIRectEdgeNone;
    
    
    NSArray *arr = @[@"消息",@"电话"];
    UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems:arr];
    CGRect segmentedControlFram = segmentedControl.frame;
    segmentedControlFram.size.width = SCREEN_W / 3;
    segmentedControl.frame = segmentedControlFram;
    segmentedControl.selectedSegmentIndex = 0;
    [segmentedControl addTarget:self action:@selector(segmentedAction:) forControlEvents:UIControlEventValueChanged];
    self.navigationItem.titleView = segmentedControl;
    
    NewsListTableViewController *nlTVC = [[NewsListTableViewController alloc] init];
    _newsListTableView = nlTVC.tableView;
    PhoneListTableViewController *plTVC = [[PhoneListTableViewController alloc] init];
    _phoneListTableView = plTVC.tableView;
    
    CGRect viewFram = _newsListTableView.frame;
    viewFram.origin.y = viewFram.origin.y - 20;
    viewFram.size.height = viewFram.size.height + 20;
    _newsListTableView.frame = viewFram;
    _phoneListTableView.frame = viewFram;
    
    _newsListTableView.hidden = NO;
    _phoneListTableView.hidden = YES;
    
    [self.view addSubview:_newsListTableView];
    [self.view addSubview:_phoneListTableView];

}
- (void)segmentedAction:(UISegmentedControl *)segmentedControl{
    
    NSInteger index = segmentedControl.selectedSegmentIndex;
    
    switch (index) {
        case 0:
            _newsListTableView.hidden = NO;
            _phoneListTableView.hidden = YES;
            
            break;
        case 1:
            _newsListTableView.hidden = YES;
            _phoneListTableView.hidden = NO;
        break;
        default:
            break;
    }
    
}

- (void)personalSetting:(UIBarButtonItem *)item{
    NSLog(@" %d | %s | %@",__LINE__,__FUNCTION__,item);
}
- (void)add:(UIBarButtonItem *)item{
    NSLog(@" %d | %s | %@",__LINE__,__FUNCTION__,item);
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
